package com.neborosoft.FlyingDog.logic.database.providers;

import com.neborosoft.FlyingDog.logic.database.AudioDataManager;
import com.neborosoft.FlyingDog.logic.database.content.identified.Album;
import com.neborosoft.FlyingDog.logic.database.content.identified.Artist;
import com.neborosoft.lib.collections.tree.MultiStepsNavigationTree;
import com.neborosoft.lib.collections.tree.NTree;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 01.12.12
 * Time: 19:38
 * To change this template use File | Settings | File Templates.
 */
public class ArtistTree extends MultiStepsNavigationTree {
    private static final int LEVELS_COUNT = 3;
    private static final int ARTIST_LEVEL = 0;
    private static final int ALBUM_LEVEL = 1;
    private static final int ARTIST_TO_SONGS_STEPS_COUNT = 1;

    public ArtistTree() {
        super(LEVELS_COUNT);
    }

    public static List getChildrenOfParentInArtistTree(Object parent, int level, int stepsCount){
        switch (level) {
            case ARTIST_LEVEL:
                Artist artist = (Artist) parent;
                if(stepsCount == 0){
                    return AudioDataManager.getInstance().getAlbumsOfArtist(artist);
                } else {
                    return AudioDataManager.getInstance().getTracksOfArtist(artist);
                }
            case ALBUM_LEVEL:
                Album album = (Album) parent;
                return AudioDataManager.getInstance().getTracksOfAlbum(album);
            default:
                throw new IllegalArgumentException("invalid level, should be 0,1");
        }
    }

    @Override
    protected List getChildrenOfParent(Object parent, int level, int stepsCount) {
        return getChildrenOfParentInArtistTree(parent, level, stepsCount);
    }

    @Override
    protected List getRootItems() {
        return getArtists();
    }

    protected List<Artist> getArtists(){
        return AudioDataManager.getInstance().getArtists();
    }
}
